using HKB.Common;
using System;
using System.Data;
namespace HKB.Web
{
	public class UserExpAction
	{
		private Conn conn;
		public UserExpAction(Conn _conn)
		{
			this.conn = _conn;
		}
		public bool AddUserExpTransaction(int UserID, long UserEP, int cType, string Remark, string ac)
		{
			long num = UserEP;
			if (ac == "-")
			{
				num = -UserEP;
			}
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserEP", DbType.Int64, num),
				this.conn.CreateParameter("@cType", DbType.Int32, cType),
				this.conn.CreateParameter("@CreateTime", DbType.DateTime, DateTime.Now),
				this.conn.CreateParameter("@Remark", DbType.String, Remark)
			};
			bool result;
			try
			{
				this.conn.ExecuteTransaction("Insert Into [HL_UserExpRecorde](UserID,UserEP,cType,CreateTime,Remark) values(@UserID,@UserEP,@cType,@CreateTime,@Remark)", parameters);
				this.conn.ExecuteTransaction(string.Concat(new object[]
				{
					"Update [HL_User] Set UserEp=UserEp",
					ac,
					UserEP,
					" Where UserID=",
					UserID
				}));
			}
			catch
			{
				result = false;
				return result;
			}
			result = true;
			return result;
		}
		public bool AddUserExpSql(int UserID, long UserEP, int cType, string Remark, string ac)
		{
			long num = UserEP;
			if (ac == "-")
			{
				num = -UserEP;
			}
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserEP", DbType.Int64, num),
				this.conn.CreateParameter("@cType", DbType.Int32, cType),
				this.conn.CreateParameter("@CreateTime", DbType.DateTime, DateTime.Now),
				this.conn.CreateParameter("@Remark", DbType.String, Remark)
			};
			bool result;
			try
			{
				this.conn.Execute("Insert Into [HL_UserExpRecorde](UserID,UserEP,cType,CreateTime,Remark) values(@UserID,@UserEP,@cType,@CreateTime,@Remark)", parameters);
				this.conn.Execute(string.Concat(new object[]
				{
					"Update [HL_User] Set UserEp=UserEp",
					ac,
					UserEP,
					" Where UserID=",
					UserID
				}));
			}
			catch
			{
				result = false;
				return result;
			}
			result = true;
			return result;
		}
		public bool AddUserExp(int UserID, long UserEP, int cType, string Remark, params Conn[] connT)
		{
			bool flag = false;
			if (connT.Length > 0 && connT[0] != null)
			{
				flag = true;
			}
			bool result;
			if (cType == 1)
			{
				string commandText = string.Concat(new object[]
				{
					"SELECT CreateTime FROM [HL_UserExpRecorde] WHERE UserID=",
					UserID,
					" AND CreateTime BETWEEN '",
					DateTime.Today.ToString("yyyy/M/dd"),
					"' AND '",
					DateTime.Today.AddDays(1.0).ToString("yyyy/M/dd"),
					"'"
				});
				object obj;
				if (flag)
				{
					obj = connT[0].ExecuteTransactionScalar(commandText);
				}
				else
				{
					obj = this.conn.GetScalar(commandText, new IDbDataParameter[0]);
				}
				if (obj != null)
				{
					result = false;
					return result;
				}
			}
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserEP", DbType.Int64, UserEP),
				this.conn.CreateParameter("@cType", DbType.Int32, cType),
				this.conn.CreateParameter("@CreateTime", DbType.DateTime, DateTime.Now),
				this.conn.CreateParameter("@Remark", DbType.String, Remark)
			};
			string commandText2 = "Insert Into [HL_UserExpRecorde](UserID, UserEP, cType, CreateTime, Remark) values(@UserID, @UserEP, @cType, @CreateTime, @Remark)";
			if (flag)
			{
				result = (this.conn.ExecuteTransaction(commandText2, parameters) == 1);
			}
			else
			{
				result = (this.conn.Execute(commandText2, parameters) == 1);
			}
			return result;
		}
	}
}
